// pages/picker/picker.js
var source=require('../../base/data/source.js');
Page({

  data: {
    flag:false,
    show:true,
    provinceName:[],
    provinceCode:[],
    privinceInsex:'',

    cityName:[],
    cityCode:[],
    cityIndex:'',

    pro:0,
    cit:0,
  },
  onLoad:function(e){
    console.log(e.id);
    this.setSource();
  },
  setSource:function(pro,cit){
    // console.log(this.data.pro);
    var pro =pro||0;
    var cit=cit||0;
    var province = source['100000'];
    console.log(province);

    var provinceName=[];
    var provinceCode=[];

    for(var item in province){
      console.log(item);
      provinceCode.push(item);
      provinceName.push(province[item]);
    }
    console.log(provinceName);
    this.setData({
      provinceName:provinceName,
      provinceCode:provinceCode
    });
    var city=source[provinceCode[pro]];
    console.log(city);
    var cityCode=[];
    var cityName=[];
    for(var item in city){
      cityCode.push(item);
      cityName.push(city[item]);
    }
    console.log(cityName);
    this.setData({
      cityName:cityName,
      cityCode:cityCode
    });
  },
  showPicker:function(){
    this.setData({
      show:false
    });
  },
  cancel: function () {
    this.setData({
      show: true
    });
  },
  pickerChange:function(e){
    var pro = e.detail.value[0];
    var cit = e.detail.value[1];
    this.setSource(pro, cit);
    this.setData({
      pro:pro,
      cit:cit
    });
  },
  sure:function(){
    this.setData({
      provinceIndex:this.data.pro,
      cityIndex:this.data.cit,
      flag:true,
    });  
    this.cancel();
    }

})